package com.hayato.demo.servlet;

import java.io.IOException;
import javax.servlet.http.*;

import com.hayato.demo.utils.Constant;

@SuppressWarnings( "serial" )
public class SettingMenuServlet extends HttpServlet {

	String page = Constant.DISP_ERROR;

	public void doGet( HttpServletRequest request, HttpServletResponse response )
			throws IOException {
		request.setCharacterEncoding( Constant.ENCODING );
		String action = request.getParameter( "action" );

		if ( action.equals( Constant.ACTION_READ_BAR_CODE ) ) {
			redirectToReadProduct( request, response );
		} else if ( action.equals( Constant.ACTION_INPUT ) ) {
			redirectToSearchProduct( request, response );
		} else if ( action.equals( Constant.ACTION_BACK ) ) {
			back( request, response );
		}
		
		response.sendRedirect( page );
	}

	public void doPost( HttpServletRequest request, HttpServletResponse response )
			throws IOException {
		doGet( request, response );
	}

	public void redirectToReadProduct( HttpServletRequest request,
			HttpServletResponse response ) throws IOException {
		page = Constant.DISP_READ_CUSTOMER;
	}

	public void redirectToSearchProduct( HttpServletRequest request,
			HttpServletResponse response ) throws IOException {
		page = Constant.DISP_SEARCH_CUSTOMER;
	}

	public void back( HttpServletRequest request,
			HttpServletResponse response ) throws IOException {
		page = Constant.DISP_SETTING;
	}
}
